package edu.pku.sei.modeler.model.notation.shape.extradata;

import org.eclipse.draw2d.Shape;
import org.w3c.dom.Element;

import edu.pku.notation.runtime.draw2d.TriangleFigure;
import edu.pku.sei.gefcommon.descriptor.annotation.EnumerationProperty;
import edu.pku.sei.gefcommon.descriptor.annotation.FieldProperty;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.notation.core.NotationPackage;
import edu.pku.sei.modeler.model.xml.XMLUtility;

public class TriangleData extends ExtraData{
	static public final int NORTH = 0;
	static public final int SOUTH = 1;
	static public final int EAST = 2;
	static public final int WEST = 3;

	@FieldProperty(catalog="Extra",name="Triangle Direction",id="SHAPE_EXTRA_TRIANGLE_DIRECTION")
	@EnumerationProperty(strings={"NORTH","SOURCE","EAST","WEST"})
	private int direction;
	
	public TriangleData(MetaModelElement host){
		super(host);
		direction = NORTH;
	}
	public int getDirection() {
		return direction;
	}
	public void setDirection(int direction) {
		this.direction = direction;
	}
	

	@Override
	public void refreshFigure(Shape shape) {
		edu.pku.notation.runtime.draw2d.TriangleFigure fig = (TriangleFigure) shape;
		fig.setDirection(direction);
		
	}
	//add by fengchao
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root, NotationPackage.TRIANGLEDATA_DIRECTION, direction);
	}
	public void deSerialize(Element root) {
		super.deSerialize(root);
		direction = XMLUtility.xmlInstance.deSerializeInt(root, NotationPackage.TRIANGLEDATA_DIRECTION);
	}
	//end add
	
}
